import { filter, from, map, mergeMap } from "rxjs";
import { WpsAirScriptCaller } from "./WpsAirScriptCaller";

export class WASSheetCaller extends WpsAirScriptCaller
{
    readSheetDataObs(sheetName: string, range: string)
    {
        return this.getRawScriptResultWithContextObs({argv:{
            "sheetName":sheetName,
            "rangeName":range,
            "runType": "read"
        }}).pipe(
            map(v => <string[]>v.data.result),
            filter(v => v != null && v != undefined),
            mergeMap(v => from(v)),
            map(v => v == null || v == undefined ? "" : v)
        )
    }
    
    writeSheetDataObs(sheetName: string, range: string, writeDataList: string[])
    {
        return this.getRawScriptResultWithContextObs({argv:{
            "sheetName":sheetName,
            "rangeName":range,
            "runType": "write",
            "writeDataList": writeDataList
        }}).pipe(
            map(v => v.data),
        )
    }

    cleanSheetDataObs(sheetName: string, range: string)
    {
        return this.getRawScriptResultWithContextObs({argv:{
            "sheetName":sheetName,
            "rangeName":range,
            "runType": "cleanAll",
        }}).pipe(
            map(v => v.data),
        )
    }
}